﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using XMLSpreadGear.Core;

namespace XMLSpreadGear.Templates
{
    public class Cell:MultiElement<Cell>
    {

         public Cell(string strlocalname)
            : base(strlocalname)
        {

        }

         public Cell(string strlocalname,
              string pasteFormula,
        string arrayRange,
        string formula,
        string href,
        ulong? index,
        ulong? mergeAcross,
        ulong? mergeDown,
        string styleID,
        string screenTip,
             Data data,
             Comment comment,
             GenericElement namedCell)
             : this(strlocalname)
         {

             this.PasteFormula = pasteFormula;
             this.ArrayRange = arrayRange;
             this.Formula = formula;
             this.HRef = href;
             this.Index = index;
             this.MergeAcross = mergeAcross;
             this.MergeDown = mergeDown;
             this.StyleID = styleID;
             this.HRefScreenTip = screenTip;
             this.dData = data;
             this.cComment = comment;
             this.geNamedCell = namedCell;
         }


        string m_PasteFormula;
        string m_ArrayRange;
        string m_Formula;
        string m_HRef;
        ulong? m_Index;
        ulong? m_MergeAcross;
        string m_StyleID;
        string m_HRefScreenTip;
        ulong? m_MergeDown;

        public string PasteFormula
        {
            get { return m_PasteFormula; }
            set { m_PasteFormula = value; }
        }       
        public string ArrayRange
        {
            get { return m_ArrayRange; }
            set { m_ArrayRange = value; }
        }
        public string Formula
        {
            get { return m_Formula; }
            set { m_Formula = value; }
        }    
        public string HRef
        {
            get { return m_HRef; }
            set { m_HRef = value; }
        }
        public ulong? Index
        {
            get { return m_Index; }
            set { m_Index = value; }
        }
        public ulong? MergeAcross
        {
            get { return m_MergeAcross; }
            set { m_MergeAcross = value; }
        }
        public ulong? MergeDown
        {
            get { return m_MergeDown; }
            set { m_MergeDown = value; }
        }
        public string StyleID
        {
            get { return m_StyleID; }
            set { m_StyleID = value; }
        }
        public string HRefScreenTip
        {
            get { return m_HRefScreenTip; }
            set { m_HRefScreenTip = value; }
        }

        private SmartTags stsmarttags;

        public SmartTags SmartTags
        {
            get { return stsmarttags; }
            set { stsmarttags = value; }
        }

        private Data dData;

        public Data Data
        {
            get { return dData; }
            set { dData = value; }
        }

        private Comment cComment;

        public Comment Comment
        {
            get { return cComment; }
            set { cComment = value; }
        }

        private GenericElement geNamedCell;

        public GenericElement NamedCell
        {
            get { return geNamedCell; }
            set { geNamedCell = value; }
        }

        internal protected override IDictionary<string, string> RegisterAttributes()
        {
            IDictionary<string, string> dic = new Dictionary<string, string>();
            if(!string.IsNullOrEmpty(this.PasteFormula))
                dic.Add("PasteFormula", this.PasteFormula);

            if(!string.IsNullOrEmpty(this.ArrayRange))
                dic.Add("ArrayRange", this.ArrayRange);

            if(!string.IsNullOrEmpty(this.Formula))
                dic.Add("Formula", this.Formula);
            if(!string.IsNullOrEmpty(this.HRef))
                dic.Add("HRef", this.HRef);
            if(this.Index != null)
                dic.Add("Index", this.Index.ToString());

            if(this.MergeAcross != null)
                dic.Add("MergeAcross", this.MergeAcross.ToString());

            if(this.MergeDown!=null)
                dic.Add("MergeDown", this.MergeDown.ToString());

            if(!string.IsNullOrEmpty(this.StyleID))
                dic.Add("StyleID", this.StyleID);

            if(!string.IsNullOrEmpty(this.HRefScreenTip))
                dic.Add("HRefScreenTip", this.HRefScreenTip);

            return dic;
        }

        internal protected override IDictionary<string, string> RegisterElements()
        {
            IDictionary<string, string> dic = new Dictionary<string, string>();
            if(this.SmartTags != null)
                dic.Add("SmartTags", this.SmartTags.ToString());

            if(this.Data != null)
                dic.Add("Data", this.Data.ToString());

            if(this.Comment != null)
                dic.Add("Comment", this.Comment.ToString());

            if(this.NamedCell != null)
                dic.Add("NamedCell", this.NamedCell.ToString());

            return dic;
        }

        internal override string GetAttributeNamespace()
        {
            return Contstants.SpredsheetAttributePrefix;
        }

        internal override string GetAttributeNamespaceURI()
        {
            return Contstants.SpredsheetAttributeNamespace;
        }
    }
}
